class Solution:
	# @param {integer} n
	# @param {integer} k
	# @return {string}
	def getPermutation(self, n, k):
		k -= 1
		ans = ""
		remain = range(1, n+1)
		p = n
		while k > 0:
			size = self.__step(p-1)
			g = k / size
			ans += str(remain[g])
			remain.pop(g)
			k = k % size
			p -= 1
		ans += "".join(str(i) for i in remain)
		return ans


	def __step(self, n):
		ans = 1
		while n > 1:
			ans *= n
			n -= 1
		return ans

if __name__ == '__main__':
	so = Solution()
	print so.getPermutation(4,7)